<?php
/**
 * Created by PhpStorm.
 * User: itboye
 * Date: 2016/12/2
 * Time: 10:26
 */

namespace Admin\Api;

use \Common\Api\Api;
use Admin\Model\IntentionalOrderModel;

class IntentionalOrderApi extends Api

{
    const QUERY = "Admin/IntentionalOrder/query";
    /**
     *
     * 删除
     */
    const DELETE = "Admin/IntentionalOrder/delete";
    /**
     *
     * 获取一条数据，根据ID
     */
    const GET_INFO = "Admin/IntentionalOrder/getInfo";
    /**
     *
     * 保存，根据ID
     */
    const SAVE_BY_ID = "Admin/IntentionalOrder/saveByID";
    /**
     *
     * 获取插件信息
     */
    const GET_LIST = "Admin/IntentionalOrder/getList";
    /**
     *
     * 获取插件的后台列表
     */
    const GET_ADMIN_LIST = "Admin/IntentionalOrder/getAdminList";
    /**
     *
     * 禁用
     */
    const DISABLE = "Admin/IntentionalOrder/disable";
    /**
     *
     * 启用
     */
    const ENABLE = "Admin/IntentionalOrder/enable";

    /**
     *
     */

    //初始化模型类
    protected function _init(){
        $this->model = new IntentionalOrderModel();
    }

    public function query($map = null, $page = array('curpage' => 0, 'size' => 10), $order = false, $params = false, $fields = false)
    {
        $model = new IntentionalOrderModel();
        $list = $model->alias('p')->field('id,create_time,p.uid as pid,p.update_time,order_items,contact_name,note,pa.nickname')
            ->join('common_member as pa ON p.uid = pa.uid', 'left')
            ->where($map)
            ->page($page)->select();
        if ($list === false) {
            $error = $this->model->getDbError();
            return $this->apiReturnErr($error);
        }
        $count =  $model->alias('p')->field('id,create_time,p.uid as pid,p.update_time,order_items,contact_name,note,pa.nickname')
            ->join('common_member as pa ON p.uid = pa.uid', 'left')
            ->where($map)
            ->count();
        $Page = new \Think\Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数
        $show = $Page->show();
        return $this->apiReturnSuc(array("show" => $show, "list" => $list));

    }
}